def prosto(n):
    b = 2
    while n % b != 0:
        b += 1
    return b == n


a = input().split()
nums = {'zero': '0', 'one': '1', 'two': '2', 'three': '3', 'four': '4', 'five': '5',
        'six': '6', 'seven': '7', 'eight': '8', 'nine': '9'}
right = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']
flag = True
for i in a:
    if i not in right:
        print('Wrong input')
        flag = False
        break
if flag is True:
    fullnum = ''
    for i in a:
        fullnum += nums.get(i)
    fullnum = int(fullnum)
    if len(str(fullnum)) != 3 or len(a) != 3:
        print('Wrong input')
    else:
        plus = fullnum
        minus = fullnum
        while prosto(plus) is False:
            plus += 1
        while prosto(minus) is False:
            minus -= 1
        if plus - fullnum <= fullnum - minus:
            print(plus)
        else:
            print(minus)
